package com.im.web.core.propertiy;

import java.beans.PropertyEditorSupport;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/** @author gongym */
public class CustomDateEditor extends PropertyEditorSupport {
  @Override
  public String getAsText() {
    Date value = (Date) getValue();
    return (value != null ? String.valueOf(TimeUnit.MILLISECONDS.toSeconds(value.getTime())) : "");
  }

  @Override
  public void setAsText(String text) throws IllegalArgumentException {
    setValue(new Date(Long.decode(text)));
  }
}
